﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace HostPc
{
    class Program
    {
        public static AWSIOTCoreSDK.Controller awsiot_controller = null;
        public static HVGSerial.Controller hvg_controller = null;
        public static Configuration hostpc_config = null;
        /// 应用程序的主入口点。
        [STAThread]
        static void Main()
        {
            /**
             * awsiot_controller主要负责处理亚马逊云物联网的连接，以及将从HVG收到的数据
             * 发送到AWSIOTCore，将从AWSIOTCOreSUB到的数据发送给HVG；
             * hvg_controller从HVG设备读取数据并PUB给AWSIOTCore，从AWSIOTCoreSUB数据并写入HVG设备**/
            hostpc_config = new HostPc.Configuration();
            hvg_controller = new HVGSerial.Controller(ref hostpc_config);
            awsiot_controller = new AWSIOTCoreSDK.Controller(ref hostpc_config);

            // 传入已连接的Adapter对象
            awsiot_controller.PassHVGController(ref hvg_controller);
            hvg_controller.PassAWSIOTCoreController(ref awsiot_controller);

            // 设置hvg和AWSIOT两个线程
            Thread __hvg = new Thread(() =>
            {
                hvg_controller.Run();
            });

            Thread __awsiot = new Thread(() =>
            {
                awsiot_controller.Run();
            });

            // 开始运行两个线程
            __hvg.Start();
            __awsiot.Start();

            // 运行窗体软件
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1 hostpc_form1 = new Form1();
            hostpc_form1.tbx_subscribe_topic.Text = awsiot_controller.awsiot_adapter.client_id;
            Application.Run(hostpc_form1);

        } // main()
    }
}
